/* 
* w_weizhen@sina.com 
*/
package com.mc.project;

import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/** 
* w_weizhen@sina.com
*/
public class ShangHaiKongTiao
{
    private static final String server_url = "http://116.128.191.178:8090/";
    
    /** <一句话功能简述>  <br>
    * <功能详细描述> 
    * @param args 
    * @see [类、类#方法、类#成员] 
    */
    public static void main(String[] args)
    {
        
        getAllPlace();
        
        
        
        
    }
    
    private static void getAllPlace()
    {
        StringBuffer url = new StringBuffer(server_url).append("conditioner/api/jzkt/selectPlace")
            .append("?name=上")
            .append("&pageNum=10")
            .append("&pageSize=");
        int pageSize = 0;
//        while (true)
//        {
//            JSONObject rsp = apiGet(url.toString() + pageSize);
//            System.out.println(rsp);
//            if(
//                !Objects.equals(rsp.getInteger("code"), 200) || 
//                Objects.isNull(rsp.getJSONObject("data")) ||
//                Objects.isNull(rsp.getJSONObject("data").getJSONArray("records"))
//            )
//            {
//                break;
//            }
//            JSONArray datas = rsp.getJSONObject("data").getJSONArray("records");
//            for (int i = 0; i < datas.size(); i++)
//            {
//                JSONObject data = datas.getJSONObject(i);
//                if (StringUtils.isNoneBlank(data.getString("managerMum")))
//                {
//                    System.out.println(data.toJSONString());
//                }
//            }
//            pageSize = pageSize + 1;
//        }
        
        
        url = new StringBuffer(server_url).append("conditioner/api/jzkt/selectPlaceById")
          .append("?id=810199");
//        
//        
//        url = new StringBuffer(server_url).append("conditioner/api/jzkt/selectConstruction")
//            .append("?name=上")
//            .append("&pageSize=0")
//            .append("&pageNum=10");
//        
//        url = new StringBuffer(server_url).append("conditioner/api/jzkt/selectConstructionById")
//            .append("?id=9772911072a44120b514cbb6cbf000cb");
//        
//        
//        url = new StringBuffer(server_url).append("conditioner/api/jzkt/updateManagerPhone")
//            .append("?phone=18518910850")
//            .append("&placeId=810199");
//        
//        url = new StringBuffer(server_url).append("conditioner/api/jzkt/selectPlaceByPhone")
//            .append("?phone=18518910850");
//        
//        List<String> types = Arrays.asList("fjxfSystem", "allAirSystem");
//        url = new StringBuffer(server_url).append("conditioner/api/jzkt/updateConstructionType")
//            .append("?placeId=810199")
//            .append("&typeList=")
//            .append(StringUtils.join(types.toArray(), ","));
        
        JSONObject rsp = apiGet(url.toString());
        System.out.println(rsp);
        
    }
    
    // 发起连接
    private static JSONObject apiGet(String url)
    {
        OkHttpClient httpClient = new OkHttpClient();
        Request request = new Request.Builder().url(url.toString()).get().build();
        try
        {
            Response response = httpClient.newCall(request).execute();
            String result = response.body().string();
            JSONObject rsp = JSONObject.parseObject(result);
            return rsp;
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return null;
    }
}